// herbs.txt v1.0
// M. G. Slack - 2004
// (slack at attglobal . net)
// Simple script that will allow searching or walking on to give a specified
// random number of herbs to the party.  Note, this script, in order to work properly,
// needs to have a 'day' counter routine added to the scenario script 'start' state.
// The routine should be similar to this:
// short daypassed;
// daypassed = get_current_tick() % 5000;
// if (daypassed == 0) {
//   if (get_flag(sdfa, sdfb) > 0)
//     inc_flag(sdfa, sdfb, -1);
//   ...
//   - do same for each of the herb locations sdfs -
//   ...
// }
//
// Memory Cells - 
//   0 - Herb to give (0-5). 214/215/216/217/218/219
//       0=Healing,1=Spiritual,2=Energetic,3=Graymold,4=Toadstools,5=Mandrake
//   1 - How many (0 = random 1-3) - will only allow up to 5.
//   2 - How many days before available again (0 = random 1-5) - will allow up to 10.
//   3,4 - Coordinates for a stuff done flag. If these are 0 and 0, will not give herbs.
//         Otherwise, number of days before regrowth is stored in the sdf set.
//         NOTE: the sdf set needs to be reset via a 'days' passed routine like above
//         or else the herb give is a one time only give...

beginterrainscript; 

variables;

short i, num, herb, choice;

string name, msg;

body;

beginstate INIT_STATE; // state 0
	if ((get_memory_cell(0) < 0) || (get_memory_cell(0) > 5))
		set_memory_cell(0, 0);
	if ((get_memory_cell(1) < 0) || (get_memory_cell(1) > 5))
		set_memory_cell(1, 0);
	if ((get_memory_cell(2) < 0) || (get_memory_cell(2) > 10))
		set_memory_cell(2, 0);
break;

beginstate START_STATE; // state 2
break;

beginstate SEARCH_STATE; // state 100
	set_state_continue(10);
break;

beginstate STEP_INTO_SPOT_STATE; // state 114
	set_state_continue(10);
break;

beginstate 10;
	if ((get_memory_cell(3) > 0) || (get_memory_cell(4) > 0)) {
		set_state_continue(11);
	}
break;

beginstate 11;
	if (get_memory_cell(0) == 1) {
		herb = 215;
		clear_buffer();
		append_string("Spiritual Herbs");
		get_buffer_text(name);
	}
	else if (get_memory_cell(0) == 2) {
		herb = 216;
		clear_buffer();
		append_string("Energetic Herbs");
		get_buffer_text(name);
	}
	else if (get_memory_cell(0) == 3) {
		herb = 217;
		clear_buffer();
		append_string("Graymold");
		get_buffer_text(name);
	}
	else if (get_memory_cell(0) == 4) {
		herb = 218;
		clear_buffer();
		append_string("Toadstools");
		get_buffer_text(name);
	}
	else if (get_memory_cell(0) == 5) {
		herb = 219;
		clear_buffer();
		append_string("Mandrake");
		get_buffer_text(name);
	}
	else { // get_memory_cell(0) == 0
		herb = 214;
		clear_buffer();
		append_string("Healing Herbs");
		get_buffer_text(name);
	}
	set_state_continue(12);
break;

beginstate 12;
	if (get_sdf(get_memory_cell(3), get_memory_cell(4)) == 0) {
		clear_buffer();
		append_string("There is a little patch of ");
		append_string(name);
		append_string(" here.");
		get_buffer_text(msg);
		reset_dialog();
		add_dialog_str(0, msg, 0);
		add_dialog_str(1, "Do you collect it?", 0);
		add_dialog_choice(0, "Leave Alone");
		add_dialog_choice(1, "Collect");
		choice = run_dialog(0);
		if (choice == 2) {
			i = get_memory_cell(2);
			if (i == 0) {
				i = get_ran(1, 1, 5);
			}
			set_flag(get_memory_cell(3), get_memory_cell(4), i);
			i = 0;
			num = get_memory_cell(1);
			if (num == 0) {
				num = get_ran(1, 1, 3);
			}
			while (i < num) {
				if (reward_give(herb) == 0) {
					// reset flag - didn't pick completly - no room
					print_str_color("The party has no room for the herb.", 4);
					set_flag(get_memory_cell(3), get_memory_cell(4), 0);
					end();
				}
				i = i + 1;
			}
			clear_buffer();
			append_string("The party collect some ");
			append_string(name);
			append_string(".");
			get_buffer_text(msg);
			print_str_color(msg, 4);
		}
	}
	else {
		clear_buffer();
		append_string("The ");
		append_string(name);
		if ((herb == 217) || (herb == 219))
			append_string(" hasn't ");
		else
			append_string(" haven't ");
		append_string("grown back yet.");
		get_buffer_text(msg);
		print_str_color(msg, 4);
	}
break;
